var request = require('request');
var cheerio = require('cheerio');


var url = 'https://www.swpu.edu.cn/rsc/bsh.htm';
var baseUrl = 'https://www.swpu.edu.cn/rsc/'

function crawler(url, callback) {
  //获取页面
  request(url, function (err, res) {
    if (err) {
      callback(err);
    }
    var $ = cheerio.load(res.body.toString()); //利用cheerio对页面进行解析
    console.log(res.body);
    var articleList = [];
    $('.t a').each(function (index,item) {
      console.log(index,item.children[0].data);
      console.log();
      let article = {
        link:baseUrl+item.attribs.href,
        title:item.children[0].data
      }
      articleList.push(article)
    });
    
    console.log(articleList);
  });
}

crawler(url, function (err, List) {
  if (err) {
    return console.log(err);
  }
  console.log(List);
});